package net.flintx.array;

import java.util.Arrays;

public class LargestNumberAtLeastTwiceOfOthers {
    public int dominantIndex(int[] nums) {
        int index = 0, maxValue = nums[0];
        for (int i = 1; i < nums.length; i++) {
            if (nums[i] >= 2 * maxValue) {
                index = i;
                maxValue = nums[i];
            }
        }
        for (int i = 0; i < nums.length; i++) {
            if (i != index && nums[i] * 2 > maxValue)
                return -1;
        }
        return index;
    }

    // 意义不明的一题。。求数组最大值是否是次大值两倍
}
